<script type="text/ecmascript-6">
	/**
	 * Created by wcz on 2016/11/29.
	 */

	import signIn from './signin.vue'
	import signUp from './signup.vue'
	import b from '../bus'

	export default {
		data () {
			return {
				currentView: 'signIn',
			}
		},
        beforeRouteEnter (to, from, next) {
            axios.get(host + '/downstreams/heartbeat', {
                withCredentials: true,
                headers: {
                    'Content-Type': 'application/json',
                    'Cache-control': 'no-cache'
                },
            }).then(res => {
                if (res.data.success) {
                    next('/home/submit');
                } else {
                    next()

                }
            })
        },
		computed: {
			isSignIn () {
				return this.currentView == 'signIn'
			}
		},
		mounted () {
			this.changeTitle('车捕头-登录');
		},
        created () {
//            this.get('/downstreams/heartbeat', {}, {slient: true}).then(res => {
//                if (res.success) {
//                    this.$router.push('/home/submit')
//                }
//            })

		  b.$on('changeview', view => {
		      this.changeSign(view)
          });
        },
		methods: {
			changeSign (page) {
				this.currentView = page
			}
		},
		components: {
			signIn,
			signUp
		}
	};
</script>

<template>
    <div class="sign">
        <div class="sign__main">
            <transition name="fade" mode="out-in">
                <component :is="currentView"></component>
            </transition>
            <!-- tab-->
            <div class="sign__tab" layout="row center-left">
                <div class="sign__tab-inner" :class="{'active': isSignIn}" @click="changeSign('signIn')">登录</div>
                <div class="sign__tab-inner" :class="{'active': !isSignIn}" @click="changeSign('signUp')">注册</div>
                <div class="sign__tab-lighter" :class="{'active': !isSignIn}"></div>
            </div>

        </div>
    </div>
</template>